/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package triploa;
import java.io.IOException;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParserException;
/**
 *
 * @author Edoardo
 */
public class Vehicle {
    private int id;
    private String model;
    private String vehicleClass;
    private String fuel;
    private String co2;
    private int seats=0;

   private Vehicle()
{
    id=0;
    model=null;
    vehicleClass=null;
    fuel=null;
    co2=null;
}
    public static final String VEHICLE_TAG="a:VehicleInfo";
public static final String ID_TAG="a:Id";
public static final String MODEL_TAG="a:Model";
public static final String VEHICLE_CLASS_TAG="a:VehicleClass";
public static final String FUEL_TAG="a:FuelConsumption";
public static final String CO2_TAG="a:Co2Emission";
public static final String MAX_SEATS_TAG="a:MaxSeatNumber";
/**
 * call for getting a new instance of this class from xml
 * @param p Parser
 * @return a new instance of FeedBack
 * @throws java.io.IOException
 * @throws org.xmlpull.v1.XmlPullParserException
 */
    public static Vehicle create(KXmlParser p)throws IOException, XmlPullParserException
{
    Vehicle l=new Vehicle();
    l.update(p);
    if(l.id==0&&l.model==null) return null;
    return l;
}
    /**
 * Update this object class from xml parser
 * @param p Parser
 * @throws java.io.IOException
 * @throws org.xmlpull.v1.XmlPullParserException
 */
public void update(KXmlParser p) throws IOException, XmlPullParserException
{
       boolean exit = false, travel = false;
        int token = -1;
        String n="",lasttag=n;
        while (!exit) {
            token = p.next();
            switch (token) {
                case KXmlParser.START_DOCUMENT:
                    break;
                case KXmlParser.END_DOCUMENT:
                    exit = true;  //exit form while
                    break;
                case KXmlParser.START_TAG:
                    System.out.println(p.getName());
                    if (p.getName().equals(VEHICLE_TAG)) {
                        travel = true;
                    }
                    if(travel) lasttag=p.getName();
                    break;
                case KXmlParser.END_TAG:
                    if (travel) {
                        if (p.getName().equals(VEHICLE_TAG)) {
                            travel = false;
                            exit = true;
                            break;
                        }
                        
                    }
                    lasttag=n;
                    break;
                case KXmlParser.TEXT:
                    if (lasttag.equals(ID_TAG)) {
                        setId(Integer.parseInt(p.getText()));
                    }
                    if (lasttag.equals(MAX_SEATS_TAG)) {
                        seats=Integer.parseInt(p.getText());
                    }
                    if (lasttag.equals(MODEL_TAG)) {
                        setModel(p.getText());
                    }
                    if (lasttag.equals(VEHICLE_CLASS_TAG)) {
                        setVehicleClass(p.getText());
                    }
                    if (lasttag.equals(CO2_TAG)) {
                        setCo2(p.getText());
                    }
                    if (lasttag.equals(FUEL_TAG)) {
                        setFuel(p.getText());
                        
                    }
                    
                    break;
            }
        }
}

    public int getId() {
        return id;
    }

    public void setId(int Id) {
        this.id = Id;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getVehicleClass() {
        return vehicleClass;
    }

    public void setVehicleClass(String vehicleClass) {
        this.vehicleClass = vehicleClass;
    }

    public String getFuel() {
        return fuel;
    }

    public void setFuel(String fuel) {
        this.fuel = fuel;
    }

    public String getCo2() {
        return co2;
    }

    public void setCo2(String co2) {
        this.co2 = co2;
    }

    public int getSeats() {
        return seats;
    }

    

    

}